import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class TestSQLWidget extends StatefulWidget {
  const TestSQLWidget({super.key});

  @override
  State<TestSQLWidget> createState() {
    return _SQLState();
  }
}

class _SQLState extends State<TestSQLWidget> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("本地数据库 SQL 学习使用"),
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Column(
          children: [
            TextButton(
              onPressed: () {
                Future f1 = Future(() async {
                  print("我是第一个");
                  String host =
                      "http://v.juhe.cn/joke/content/list.php?sort=desc&page=1&pagesize=20&time=1418816972&key=c68a247a2a65c9c96c91e1c100c61cc3";
                  var dio = Dio();

                  Response response = await dio.get(host);
                  print(response.data.toString());
                });
                f1.then((_) => print("f1 then"));
                print("我是main");
              },
              child: Text("基本网络请求 Get"),
            ),
            TextButton(
              onPressed: () async {
                String host =
                    "http://v.juhe.cn/joke/content/list.php?sort=desc&page=1&pagesize=20&time=1418816972&key=c68a247a2a65c9c96c91e1c100c61cc3";
                var dio = Dio();
                dio.interceptors.add(LogInterceptor());
                Response response = await dio.get(host,
                    options: Options(headers: {
                      "Content-Type": "application/x-www-form-urlencoded",
                    }));
                print(response.data.toString());
              },
              child: Text("基本网络请求 Get"),
            ),
          ],
        ),
      ),
    );
  }
}
